#include "map.h"
map::map(string name)
{
	mapElements=new list<mapElement>();
	graphical *sprite;
	ifstream file;
	string tileName;
	mapElement *element;
	int count,x,y,size;
	Uint32 rgbKey;
	file.open(name.c_str());
	file>>size;
	map::size=size;
	while(!file.eof())
	{
		file>>tileName;
		file>>x;//xMatch and yMatch
		file>>y;
		file>>rgbKey;
		sprite=new graphical(tileName, rgbKey, true, x, y);
		file>>count; //count of objects on the map
		for(int i=0;i<count;i++)
		{
			file>>x; //coordinates on the map
			file>>y;
			element=new mapElement;
			element->link=sprite;
			element->x=x;
			element->y=y;
			mapElements->push_front(*element);
		}
	}
	file.close();
}
map::~map()
{
	delete mapElements;
}
void map::Generate(string name)
{
	ofstream file;
	string tileName="tiles\\wasteland.bmp";
	int count=40,x=0,y=0;
	Uint32 rgbKey=0x0;
	file.open(name.c_str());
	file<<1280;
	file<<'\n';
	for(int j=0;j<40;j++)
	{
		x=0;
		y=j*32;
		file<<tileName;
		file<<' ';
		file<<0;//xMatch and yMatch
		file<<' ';
		file<<0;
		file<<' ';
		file<<rgbKey;
		file<<' ';
		file<<count; //count of objects on the map
		file<<' ';
		for(int i=0;i<count;i++)
		{
			file<<x; //coordinates on the map
			file<<' ';
			file<<y;
			file<<' ';
			x+=32;
		}
		file<<'\n';
	}
	file.close();
}